package com.ruoyi.project.data.InvalidBooks.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.InvalidBooks.domain.FailedBooksInfo;
import com.ruoyi.project.data.InvalidBooks.service.IFailedBooksInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 失效书籍信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-27
 */
@Controller
@RequestMapping("/data/InvalidBooks")
public class FailedBooksInfoController extends BaseController
{
    private String prefix = "data/InvalidBooks";

    @Autowired
    private IFailedBooksInfoService failedBooksInfoService;

    @RequiresPermissions("data:InvalidBooks:view")
    @GetMapping()
    public String InvalidBooks()
    {
        return prefix + "/InvalidBooks";
    }

    /**
     * 查询失效书籍信息列表
     */
    @RequiresPermissions("data:InvalidBooks:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FailedBooksInfo failedBooksInfo)
    {
        startPage();
        List<FailedBooksInfo> list = failedBooksInfoService.selectFailedBooksInfoList(failedBooksInfo);
        return getDataTable(list);
    }

    /**
     * 导出失效书籍信息列表
     */
    @RequiresPermissions("data:InvalidBooks:export")
    @Log(title = "失效书籍信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FailedBooksInfo failedBooksInfo)
    {
        List<FailedBooksInfo> list = failedBooksInfoService.selectFailedBooksInfoList(failedBooksInfo);
        ExcelUtil<FailedBooksInfo> util = new ExcelUtil<FailedBooksInfo>(FailedBooksInfo.class);
        return util.exportExcel(list, "失效书籍信息数据");
    }

    /**
     * 新增失效书籍信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存失效书籍信息
     */
    @RequiresPermissions("data:InvalidBooks:add")
    @Log(title = "失效书籍信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FailedBooksInfo failedBooksInfo)
    {
        return toAjax(failedBooksInfoService.insertFailedBooksInfo(failedBooksInfo));
    }

    /**
     * 修改失效书籍信息
     */
    @RequiresPermissions("data:InvalidBooks:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FailedBooksInfo failedBooksInfo = failedBooksInfoService.selectFailedBooksInfoById(id);
        mmap.put("failedBooksInfo", failedBooksInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存失效书籍信息
     */
    @RequiresPermissions("data:InvalidBooks:edit")
    @Log(title = "失效书籍信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FailedBooksInfo failedBooksInfo)
    {
        return toAjax(failedBooksInfoService.updateFailedBooksInfo(failedBooksInfo));
    }

    /**
     * 删除失效书籍信息
     */
    @RequiresPermissions("data:InvalidBooks:remove")
    @Log(title = "失效书籍信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(failedBooksInfoService.deleteFailedBooksInfoByIds(ids));
    }
}
